/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.quangtin3.mb;

import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import org.quangtin3.entity.CollectedValue;
import org.quangtin3.entity.Collection;
import org.quangtin3.entity.CollectionColumn;
import org.quangtin3.entity.User;
import org.quangtin3.sb.CollectedValueFacade;

/**
 *
 * @author Quang
 */
@Named(value = "collectedValueManager")
@SessionScoped
public class CollectedValueManager implements Serializable {

    @EJB
    private CollectedValueFacade collectedValueFacade;
    private List<CollectedValue> collectedValues;

    /**
     * Creates a new instance of CollectedValueManager
     */
    public CollectedValueManager() {
    }

    public String onPrepareCollect(Collection collection, User user) {
        for (CollectionColumn column : collection.getCollectionColumnList()) {
            CollectedValue cv = collectedValueFacade.find(column, user);
            cv.setValue(column.getDefaultValue());
            collectedValues.add(cv);
        }
        return "collect";
    }

    public String onSave() {
        collectedValueFacade.save(collectedValues);
        return "collect";
    }

    public List<CollectedValue> getCollectedValues() {
        return collectedValues;
    }
}
